Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add XPNFTToken with MetadataGenerator #12

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

gravityblast
Copy link
Member

@gravityblast gravityblast commented Oct 4, 2024

base PoC of the XP NFT Token with dynamic on-chain metadata with info from the XP Token

output of the tokenUri function:

{
  "name": "XPNFT Token 0x123123...",
  "description": "This is a XPNFT token for address 0x123123... with balance 10",
  "image": ...SVG_BASE64_ENCODED...
}

with SVG_BASE64_ENCODED as the base64 of:

<svg xmlns="http://www.w3.org/2000/svg" height="200" width="200">
  <rect width="100%" height="100%" fill="blue"/>
  <text x="50%" y="50%" fill="white" font-size="20" text-anchor="middle">10</text>
</svg>

that renders like the following image:

nft

closes #37

@gravityblast gravityblast marked this pull request as draft October 4, 2024 13:22
@gravityblast gravityblast changed the base branch from xp-nft-token to main October 9, 2024 09:50
@gravityblast gravityblast changed the title feature: add XPNFTMetadataGenerator feature: add XPNFTToken with MetadataGenerator Oct 9, 2024
@gravityblast gravityblast marked this pull request as ready for review October 9, 2024 15:22
Copy link
Collaborator

@0x-r4bbit 0x-r4bbit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very well done. This is pretty much what I had imagined.

function balanceOf(address account) external view returns (uint256);
}

contract XPNFTToken is Ownable {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a nitpick: shall we make this Ownable2step?

}

function mint() external {
emit Transfer(msg.sender, msg.sender, uint256(uint160(msg.sender)));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate on why we're doing it this way again?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see, so an account's address is essentially the ID for the token.
This means every account automatically "owns" this NFT with most of them having 0 XP

function tokenURI(uint256 tokenId) external view onlyValidTokenId(tokenId) returns (string memory) {
address account = address(uint160(tokenId));
uint256 balance = xpToken.balanceOf(account);
return metadataGenerator.generate(account, balance);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice

@0x-r4bbit
Copy link
Collaborator

This is not passing the linter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Ready to Merge
Development

Successfully merging this pull request may close these issues.

Implement first version of XP NFT contract
2 participants